package web;

import bean.Food;
import impl.UserDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/addfood")
public class AddFoodServlet extends HttpServlet {
    private int h;
    private UserDaoImpl userDao = new UserDaoImpl();
    private Food food = new Food();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("UTF-8");

        food.setFoodname(req.getParameter("foodname"));
        food.setPrice(req.getIntHeader("price"));
        food.setAddress(req.getParameter("address"));
        food.setData(req.getParameter("data"));


        h = userDao.setFood(food);

        if(h>0){
            req.getRequestDispatcher("/main.jsp").forward(req,resp);
        }else {
            req.getRequestDispatcher("/AddFood.jsp").forward(req,resp);
        }

    }
}
